<?php 
    // Connect Database
	require('sessao.inc');
	
    // Execute Query in the right order 
    //(value,text)
    $query = "SELECT codigo, nome FROM tb_estados ORDER BY nome ASC";
    $result = mysql_query($query);
    $items = array();
    if($result && 
       mysql_num_rows($result)>0) {
        while($row = mysql_fetch_array($result)) {
            $items[] = array( $row[0], utf8_encode($row[1]) );
        }        
    }

    // convert into JSON format and print
    echo json_encode($items);
?> 